
function Clock() {
	var date = new Date();
	this.year = date.getFullYear();
	this.month = date.getMonth() + 1;
	this.date = date.getDate();
	this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()];
	this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
	this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
	this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();

	this.toString = function() {
		return this.year + "年" + this.month + "月" + this.date + "日 " + this.hour + ":" + this.minute + ":" + this.second + " " + this.day; 
	};
	
	this.toSimpleDate = function() {
		return this.year + "-" + this.month + "-" + this.date;
	};
	
	this.toDetailDate = function() {
		return this.year + "-" + this.month + "-" + this.date + " " + this.hour + ":" + this.minute + ":" + this.second;
	};
	
	this.display = function(ele) {
		var clock = new Clock();
		ele.innerHTML = clock.toString();
		window.setTimeout(function() {clock.display(ele);}, 1000);
	};
}
//时间格式化
function changetime(dateTimeStamp){
		var minute = 1000 * 60;
		var hour = minute * 60;
		var day = hour * 24;	 	
		var now = new Date();
		var old;
		var diffValue;
		if(!+[1,]){
			//"ie浏览器";
			dateTimeStampt=dateTimeStamp.replace("T"," ");
			
			old= new Date(Date.parse(dateTimeStamp.replace(/-/g,   "/")));
			diffValue = now.getTime() - (old.getTime()-3600000);
		}else{
			old=new Date(dateTimeStamp);
			diffValue = now.getTime() - old.getTime();
		}
		var dayC =diffValue/day;
		var hourC =diffValue/hour;
		var minC =diffValue/minute;
		 	
		 if(dayC>=3){
			  
			 if(now.getFullYear()==old.getFullYear()){
				 	time= dateTimeStamp.replace("T"," ");
					return time.substring(time.indexOf("-")+1,time.length);
				
				 
			 }else{
				 return dateTimeStamp.replace("T"," ");
			 }
		 }else if(dayC>=2){
			 return "前天 "+dateTimeStamp.split("T")[1];
		 }else if(dayC>=1){
			 return "昨天 "+dateTimeStamp.split("T")[1];
		 }else if(hourC>=1){
		 	return parseInt(hourC) +"小时前";
		 }else if(minC>=1){
		 	return parseInt(minC) +"分钟前";
		 }else{
		 	return Math.floor(diffValue/1000)+"秒前";
		 }	 
	}

//精确乘法运算结果 
function accMul(arg1,arg2){
	var m=0,s1=arg1.toString(),s2=arg2.toString();
	try{m+=s1.split(".")[1].length;}catch(e){}
	try{m+=s2.split(".")[1].length;}catch(e){}
	return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m);
}